<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
 <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<script src="${basePath}commonJs/jquery.ztree.all.js"></script>
<title>嘉童游乐中心-商品信息</title>
<SCRIPT type="text/javascript">
	//标记被选中节点
	var selectNode=null;
	var treeNodes=[];
	//只允许查询存在库存的商品
	var resverseTypes=[6,61];
	var resverseTypesVal=[6,61];
	var setting = {
		data: {
			simpleData: {
				enable: true
			}
		},
		callback:{
			onClick:zTreeOnClick
		}
	};
	$(document).ready(function(){
		$("#branIdSelect option[value='${branId}']").attr("selected",true);
		refreshSelect();
		$("#fkBranId").val("${branId}");
		$("#resverseTypes").val(resverseTypesVal.join());
		$("#resverseTypes2").val(resverseTypesVal.join());
		initTable("stockQueryForm");
		getTreeData();
		$.fn.zTree.init($("#sptree"), setting, treeNodes);
		setDefaultForTree();
	});

	//设置ztrre默认选中,以及样式
	function setDefaultForTree(){
		$("#sptree_1_a").addClass("curSelectedNode");
		selectNode=treeNodes[0];
	}
	
	/*获得商品分类的信息*/
	function getTreeData()
	{
		$.ajax({
			url:"${basePath}scmInvocing/productInfo/findCategoryList.shtml",
			data:{"resverseTypes":resverseTypes.join()},
			dataType:"json",
			type:"post",
	 		async:false,
			success:function(result)
			{
				var node;
				$(result).each(function(id,item)
					{
					if(id==0)
					{
    	 				node={id:item.pkPrdcateId,pId:item.fkParPrdcateId,name:item.cateName,open:true,reserveFlag:item.reserveFlag,resverseType:item.resverseType};
   	 				}else
   	 				{
    	 				node={id:item.pkPrdcateId,pId:item.fkParPrdcateId,name:item.cateName,reserveFlag:item.reserveFlag,resverseType:item.resverseType};
   	 				}
					treeNodes.push(node);
					});
			},
			error : function(XMLHttpRequest) {
				ajaxError(XMLHttpRequest);
			}
		});
	}
	
	function zTreeOnClick(event, treeId, treeNode) {
		selectNode = treeNode;// 每次点击赋值 
		//点击根节点，显示所有商品
		if(selectNode.getParentNode() == null)
			{
				var selectId = [];
				selectId = getSelectIds(selectId, treeNode);
				$("#selectId").val(selectId.join());
				select1("stockQueryForm");
			}
		else
			{
				$("#sptree_1_a").removeClass("curSelectedNode");
				//选中的商品id
				var selectId=[];
				selectId = getSelectIds(selectId,treeNode);
				$("#selectId").val(selectId.join());
				select1("stockQueryForm");
			}
	};
	
	//嵌套循环获得被选中商品及其子类商品的id
	
	function getSelectIds(selectId, treeNode) {

		selectId.push(treeNode.id);

		if (treeNode.isParent) {

			for ( var obj in treeNode.children) {

				getSelectIds(selectId, treeNode.children[obj]);
			}
		}

		return selectId;
	}

	function initTable(formId) {//库存查询分页显示
		var prdIdValue = $.trim($("#pkPrdIdValue").val());
		$("#pkPrdId").val(prdIdValue);
		var prdName = $.trim($("#prdNameValue").val());
		$("#prdName").val(prdName);
		var form = $("#" + formId);
		var pagenbean = new PageBean(form);
		pagenbean.setTableId("stockQueryTable");
		pagenbean.setCallback(callback);
		pagenbean.setFootId("stockQueryFoot");
		setPagebeanObj(pagenbean);
		pagenbean.doPage();
	}

	function callback(data) {
		if (data == null) {
			return;
		}
		$.each(data, function(ind, obj) {
			var i = ind + 1;
			var htm = "<tr>";
			var num = (obj.stgCnt == null ? 0 : obj.stgCnt);
			var storNum = obj.minStorage;
			if (storNum != null && storNum > num) {
				htm = "<tr class=\"bg_red\">";
			}
			htm += "<td>" + i + "</td>";
			htm += "<td>" + obj.pkPrdId + "</td>";
			htm += "<td>" + (obj.prdName == null ? "" : obj.prdName) + "</td>";
			htm += "<td>" + (obj.cateName == null ? "" : obj.cateName)+ "</td>";
			htm += "<td>" + (obj.prdSpec == null ? "" : obj.prdSpec) + "</td>";
			htm += "<td>" + (obj.unitName == null ? "" : obj.unitName)+ "</td>";
			htm += "<td>" + num + "</td></tr>";

			$("#stockQueryTable").find("tr:eq(" + ind + ")").after(htm);
		});
	}
	//设置pageNo为1
	function select1(formId) {
		$("#" + formId + " input:hidden[name='pageNo']").val(1);
		initTable(formId);
	}
	
	//跟换门店
	function branSelectFun() {
		$("#fkBranId").val($("#branIdSelect").val());
	}
</SCRIPT>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
          	<shiro:hasPermission name="StockGoodsIn/toStock_goodsIn.shtml">
				<li><a href="${basePath}StockGoodsIn/toStock_goodsIn.shtml"><i class="nav_icon_b"></i><br>商品入库</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="StockQuery/toStockQuery.shtml">
				<li class="content_hover"><a href="${basePath}StockQuery/toStockQuery.shtml"><i class="nav_icon_b"></i><br>库存查询</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="StockGoodsOut/toStockGoodsOut.shtml">
				<li><a href="${basePath}StockGoodsOut/toStockGoodsOut.shtml"><i class="nav_icon_b"></i><br>商品出库</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="StockTaking/toStockTaking.shtml">
				<li><a href="${basePath}StockTaking/toStockTaking.shtml"><i class="nav_icon_a"></i><br>库存盘点</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="StockCorrect/toStockCorrect.shtml">
				<li><a href="${basePath}StockCorrect/toStockCorrect.shtml"><i class="nav_icon_f"></i><br>库存调整</a></li>
			</shiro:hasPermission>
        </ul>
    </div>
    <div class="content_r mt10">
    	<div class="p20">
    	<div class="file_single_dl f14 fixed">
        	<dl class="fixed" style="overflow:hidden; float:left">
            	<dd><label>商品编号：</label><input type="text" class="iput_t w200" id="pkPrdIdValue"></dd>
                <dd><label>商品名称：</label><input type="text" class="iput_t w200" id="prdNameValue"></dd> 
                <dd><label>所属门店：</label>
                	<!----select--->
                    <div class="uboxstyle">
                       <select name="branIdSelect" id="branIdSelect" onchange="branSelectFun();">
                      		<c:forEach items="${branList}" var="bran">
                      			<option value="${bran.pkBranId}">${bran.branName}</option>
                      		</c:forEach>
                      	</select>
                    </div>
                    <!----select--->
                </dd>
            </dl>
            <div>
              <input type="button" class="btn fr" value="查询" onclick="select1('stockQueryForm');">
            </div>
        </div>
       
        <div class="tab_normal mt10">
            <ul class=" fixed" id="tab_a"></ul>
            <div class="payment_l tc" style="width: 200px ; height: 400px !important;">
                <div class="ztree m10" id="sptree" style="overflow-y: auto;width: 180px; height: 380px;" >
                </div>
            </div>
          	<ul class="fixed" id="tab_conbox_a">
                <li class="p10" style="margin-left:218px">
                	<table class="table" id="stockQueryTable">
                    	<tr> 
                        	<th>序号</th>
                            <th>商品编号</th>
                            <th>商品名称</th>
                            <th>商品分类</th>
                            <th>规格</th>
                            <th>计量单位</th> 
                            <th>库存数量</th>
                        </tr>
                    </table>
                    <!---翻页-->
                    <div class="page fr m10" id="stockQueryFoot"></div>
                    <!----->
                </li>
                </ul>
                </div>
        </div>
    </div>
</div>
	<form action="${basePath}StockQuery/findProductListForStock.shtml" id="stockQueryForm" method="post">
		<input type="hidden" name="pageNo" value="1">
		<input type="hidden" name="pageSize" value="10">
		<input type="hidden" name="pkPrdId" id="pkPrdId">
		<input type="hidden" name="prdName" id="prdName">
		<input type="hidden" name="fkBranId" id="fkBranId">
		<input type="hidden" name="selectId" id="selectId">
		<input type="hidden" name="resverseTypes" id="resverseTypes"/>
	</form>
	
	<form action="${basePath}StockQuery/findProductListForStock.shtml" id="allstockQueryForm" method="post">
		<input type="hidden" name="pageNo" value="1">
		<input type="hidden" name="pageSize" value="10">
		<input type="hidden" name="pkPrdId" id="pkPrdId">
		<input type="hidden" name="fkBranId" id="fkBranId">
		<input type="hidden" name="prdName" id="prdName">
		<input type="hidden" name="resverseTypes" id="resverseTypes2"/>
	</form>
<!---弹出层 成员信息编w辑--->
<div id="addfl" class="easyui-window" title="新增分类" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:400px; height:150px;position:relative;">
	<div class="editor_h1 fixed">
      <div class="editor fl">
            <ul>
                <li><label>分类名称：</label><input type="text" class="iput_t w160"></li>
            </ul>
        </div>
    </div>
    <div class="btm_btn btm_bg">
    	<dl>
        	<dd><input type="button" class="btn" onClick="$('#addfl').window('close')" value="确定"></dd>
            <dd><input type="button" class="btn" onClick="$('#addfl').window('close')" value="取消"></dd>
        </dl>
    </div>
</div>
</body>
</html>